package yogaService

import (
	"duoke/model"
	"duoke/model/yogaModel"
	"duoke/service/common"
	"duoke/utils/gconv"
	"errors"
	"github.com/gin-gonic/gin"
	"xorm.io/xorm"
)

var Album = new(albumService)

type albumService struct{}

func (s *albumService) Search(c *gin.Context, req map[string]interface{}) (*[]yogaModel.RspHome,
	int64, error) {
	albumType := gconv.Int(req["album_type"])
	name := gconv.String(req["name"])
	if albumType == 0 {
		return nil, 0, errors.New("参数缺失【name】")
	}
	pageNo := gconv.Int(req["pageNo"])
	pageSize := gconv.Int(req["pageSize"])
	var session *xorm.Session
	switch albumType {
	case 1:
		session = common.Tales.List(c, &model.ReqList{
			PageNo:   pageNo,
			PageSize: pageSize,
			Keyword:  name,
		}).Table("yoga_group_class")
	case 2:
		session = common.Tales.List(c, &model.ReqList{
			PageNo:   pageNo,
			PageSize: pageSize,
			Keyword:  name,
		}).Table("yoga_teacher")
	case 3, 4, 5, 6:
		session = common.Tales.List(c, &model.ReqList{
			PageNo:   pageNo,
			PageSize: pageSize,
			Keyword:  name,
		}).Table("yoga_venue")
	default:
		return nil, 0, errors.New("参数错误【album_type】")
	}
	var m []yogaModel.RspHome
	count, err := session.Cols("id,name").FindAndCount(&m)
	return &m, count, err
}
